<template>
    <el-cascader
  	  :disabled="loading"
  	  v-model="parentId"
      :options="nodeOptions"
      :props="props"
      :show-all-levels="false"
      placeholder="根节点"

      filterable
      clearable></el-cascader>
</template>

<script>

import ApiMain from '@/api/system.node';

export default {
  mixins: [
  ],
  props: [
  	'value',
  ],
  data () {
    return {

		loading : false,
		parentId: this.value,

		props: {
			checkStrictly: true, 
			emitPath     : false,
		},

		nodeOptions: [],
    }
  },
  mounted () {
  	this.fetchOptions();
  },

  watch: {
  	parentId: function (val, old) {
  		this.$emit('on-change', val);
  	},
  	value: function (val, old) {
  		this.parentId = val;
  	},
  },

  methods: {

  	async fetchOptions () {

  		this.loading = true;

  		try {
  			var re = await ApiMain.getNodeOptions({});
  			this.nodeOptions = re.tree;
  		} catch (err) {
			this.nodeOptions = [];
  		}

  		this.loading = false;
  		this.parentId = this.value;
  	},
  }
}
</script>

<style>

</style>
